// page/myApponitment/myAppointment.js

var app=getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    appointmentList:[
      {"targetDate":"2017-11-11","id":1},
      {"targetDate": "2017-11-11","id":2}
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  hello:function(e){
    console.log(e.target.id)
  },


  check_delete(e){
    var page=this;
    var id=e.target.id;

    wx.showModal({
      title: '确认消息',
      content: '您确认要取消订单吗',
      success: function (res) {
        if (res.confirm) {
          page.do_deleteById(id)
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  do_deleteById:function(id){
    var page=this;
    wx.request({
      url: 'http://localhost:8080/kc4s/appointment/deleteById',
      data: {
        id:id
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },

      method: "GET",
      success: function (res) {
        console.log(res)
        page.do_getByCustomerPhoneNum()

        wx.showToast({
          title: '删除成功',
          icon: 'success',
          duration: 1000
        })

      }
    })
  },

  do_getByCustomerPhoneNum:function (){
    var page = this
    wx.request({
      url: 'http://localhost:8080/kc4s/appointment/getByCustomerPhoneNum', 
      data: {
        customerPhoneNum:app.data.customer.phoneNum
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },

      method: "GET",
      success: function (res) {
        console.log(res.data)
        page.setData({
          appointmentList:res.data
        })
      }
    })
  },

  onLoad: function (options) {
    this.do_getByCustomerPhoneNum()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})